import React, {Component} from 'react';
import { Form, Input, Button,message} from 'antd';
import storageUtil from "../../../utils/storageUtil";

class NewOrder extends Component {
    render() {
        const { TextArea } = Input;

        const uid = storageUtil.getUser().uid

        const layout = {
            labelCol: { span: 10 },
            wrapperCol: { span: 30 },
        };

        const tailLayout = {
            wrapperCol: { offset: 8, span: 16 },
        };

        const onFinish = (values: any) => {

            values.uid = uid
            console.log(values)

            this.$myAxios.post('/order/addOrder',values).then(res => {
                if(res.data){
                    message.success("添加成功")
                    this.props.history.push('/admin/myOrder')
                }
                else{
                    message.error("添加失败，请重新添加")
                }
            })
        };

        const onFinishFailed = (errorInfo: any) => {
            console.log('Failed:', errorInfo);
        };

        return (
            <Form
                {...layout}
                style={{float: 'left'}}
                name="basic"
                initialValues={{ remember: true }}
                onFinish={onFinish}
                onFinishFailed={onFinishFailed}
            >

                <Form.Item
                    style={{width: '500px',marginLeft: '20px'}}
                    label="主题"
                    name="theme"
                    rules={[{ required: true, message: 'Please input your theme!' }]}
                >
                    <Input
                    />
                </Form.Item>

                <Form.Item
                    style={{width: '500px',marginLeft: '20px'}}
                    label="问题"
                    name="question"
                    rules={[{ required: true, message: 'Please input your question!' }]}
                >
                    <TextArea
                        showCount maxLength={100} />
                </Form.Item>

                <Form.Item
                    style={{marginLeft: '390px'}}
                    {...tailLayout}>
                    <Button type="primary" htmlType="submit">
                        提交工单
                    </Button>
                </Form.Item>
            </Form>
        );
    }
}

export default NewOrder;